package com.lmt.ymcc.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.lmt.ymcc.domain.MessageBlacklist;
import com.lmt.ymcc.domain.MessageSms;
import com.lmt.ymcc.mapper.MessageBlacklistMapper;
import com.lmt.ymcc.mapper.MessageSmsMapper;
import com.lmt.ymcc.result.JSONResult;
import com.lmt.ymcc.service.IMessageSmsService;
import com.lmt.ymcc.utils.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author AmazingXu
 * @since 2022-08-06
 */
@Service
public class MessageSmsServiceImpl extends ServiceImpl<MessageSmsMapper, MessageSms> implements IMessageSmsService {

    @Autowired
    private MessageSmsMapper messageSmsMapper;

    @Autowired
    private MessageBlacklistMapper blacklistMapper;

    // 拉入黑名单
    @Override
    public JSONResult blacklisted(Long id) {
        // 通过id查询此用户的信息
        MessageSms messageSms = messageSmsMapper.selectById(id);
        AssertUtil.isNotNull(messageSms, "没有此用户");
        MessageBlacklist messageBlacklist = new MessageBlacklist();
        messageBlacklist.setCreateTime(new Date());
        messageBlacklist.setUserId(messageSms.getUserId());
        messageBlacklist.setAuditId(-1L);
        messageBlacklist.setIntro("测试");
        // 存黑名单信息
        blacklistMapper.insert(messageBlacklist);
        // 删除原表信息
        messageSmsMapper.deleteById(id);
        return JSONResult.success();
    }
}
